
var phoneReg = /^1[345789][0-9]{9}$/;
var pwdReg = /^.{6,16}$/;
var isPhoneRight=false;
var isPwdRight = false;

phone.onkeyup = function(){
    var phoneValue = phone.value;
    if(!phoneReg.test(phoneValue)){
        phoneerror.innerHTML="电话号码格式有误！";
        isPhoneRight=false;
    }else{
        phoneerror.innerHTML="";
        isPhoneRight=true;
    }

};

pwd.onkeyup = function(){
    var pwdValue = pwd.value;
    if(!pwdReg.test(pwdValue)){
        pwderror.innerHTML="密码错误，请核对后再输入！";
        isPwdRight= false;
    }else{
        pwderror.innerHTML="";
        isPwdRight=true;
    }
    checkAll();
};

var loginBtn = document.getElementById("loginBtn");
function checkAll(){
    if(isPhoneRight&&isPwdRight){
        loginBtn.className="loginBtn_active";
    }else{
        loginBtn.className="loginBtn";
    }
}

loginBtn.onclick=function(){
    if(this.className!="longinBtn"){
        loginBtn.value="登陆中";
        $.post("http://test.hfjava.com/shop/userlogin",$("form").serialize(),function(data){
            loginBtn.value="登录";
            if(data=="false"){
                pwderror.innerHTML="您的用户名或密码有误，请您重试";
            }else{
                location.href="index.html?phone="+phone.value;
            }
        })
    }
};
















/*
var rightTel = "18009688825";
var rightPassword = "lss12345";


login.onclick= function(){
    if(rightTel==phone.value){
        phoneerror.innerHTML="<img src='images/dui.png'>";
        if(rightPassword==p.value){
            perror.innerHTML="<img src='images/dui.png'>";
            alert("登录成功！")
        }else{
            perror.innerHTML="<img src='images/chahao.png'>"
        }
    }else{
        phoneerror.innerHTML="<img src='images/chahao.png'>"
    }
}
*/